<?php

// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------

namespace app\common\controller;
use think\facade\Db;

/**
 * Class AdminController
 * @package app\common\controller
 */
class Note
{
    private $code = "";
    private $expirationTime = 10;//分钟
    private $store_id = 0;
    private $mobile = "";
    //短信通道（吉信通）
    private $url = "http://service.winic.org:8009/sys_port/gateway/index.asp?";
    private $content = "";
    private $account = "nmgchemeijia";
    private $pwd = "chemeijia123";
    private $length = 6;



    public function __construct($mobile,$store_id)
    {
        $this->store_id = $store_id;
        $this->mobile = $mobile;

    }

    //短信通知方法
    private function smsInterface(){
        /*$url = $this->url;
        $data = "id=%s&pwd=%s&to=%s&Content=%s&time=";
        $id = urlencode(iconv("utf-8","gb2312","nmgchemeijia"));
        $pwd = $this->pwd;
        $to = $this->mobile;
        $this->content = urlencode(iconv("UTF-8","GB2312",$this->content));
        $rdata = sprintf($data, $id, $this->pwd, $to, $this->content);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        $result = curl_exec($ch);
        curl_close($ch);

        return $result;*/
        $data = [
            'code' => $this->code,
            'create_time' => time(),
            'mobile' => $this->mobile,
            'store_id' => $this->store_id,
            'out_date_time' => time() + ($this->expirationTime)*60,


        ];
        Db::name('note') -> insertGetId($data);
    }

    public function setCode(){
        $data = range(0,9);
        shuffle($data);
        $newArr = array_slice($data,0,$this->length);
        $this->code = implode('', $newArr);
        $this->content = "您正在消费,短信验证码是{$this->code}，切勿转发或者告知他人。";
        $this->smsInterface();
    }

   

}
